using System;
using System.Collections.Generic;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Audio;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.GamerServices;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;
using Microsoft.Xna.Framework.Net;
using Microsoft.Xna.Framework.Storage;

namespace marbletrack
{
    /// <summary>
    /// Summary description for Class1
    /// </summary>
    public class SlopePiece : TrackPiece
    {

        public SlopePiece()
        {
            // Setup variables to default values
            Vector3 rotation = Vector3.Zero;
            SetupVariables(rotation, Game1.SCALE);
        }

        public SlopePiece(Vector3 rotation, float scale)
        {
            // Setup Variables with specified values
            SetupVariables(rotation, scale);
        }

        // Setup Variables
        private void SetupVariables(Vector3 rotation, float scale)
        {
            // Setup orientation variables
            modelRotation_ = rotation;
            modelScale_ = scale;
            CorrectPosition_ = Matrix.CreateTranslation(-Game1.SQUARESIZE, -Game1.HALFSQUARESIZE, 0);
            // Load model
            model_ = Game1.SlopeModel;

            // Create and Load physics actor
            trackActor_ = CreateMeshActor();
        }

        public override void SetEntryExitPoints()
        {
            exitDirection_ = modelRotation_;
            exitPoint_ = nextModelPosition_;
            if (modelRotation_ == directionFromWest)
            {
                exitPoint_.X += Game1.SQUARESIZE * 2f;
            }
            else if (modelRotation_ == directionFromNorth)
            {
                exitPoint_.Z += Game1.SQUARESIZE * 2f;
            }
            else if (modelRotation_ == directionFromEast)
            {
                exitPoint_.X -= Game1.SQUARESIZE * 2f;
            }
            else if (modelRotation_ == directionFromSouth)
            {
                exitPoint_.Z -= Game1.SQUARESIZE * 2f;
            }
            exitPoint_.Y -= Game1.SQUARESIZE;
        }
        #region Old Saver Method (Saver 1)
        /*
        public static void FromStringList(List<string> savedStuff)
        {
            Game1.modelList.Add(new SlopePiece(
                new Vector3((float)Convert.ToDouble(savedStuff[1]),
                            (float)Convert.ToDouble(savedStuff[2]),
                            (float)Convert.ToDouble(savedStuff[3])),
                (float)Convert.ToDecimal(savedStuff[4])));
            ((SlopePiece)Game1.modelList[Game1.modelList.Count - 1]).nextModelPosition_.X = (float) Convert.ToDouble(savedStuff[5]);
            ((SlopePiece)Game1.modelList[Game1.modelList.Count - 1]).nextModelPosition_.Y = (float) Convert.ToDouble(savedStuff[6]);
            ((SlopePiece)Game1.modelList[Game1.modelList.Count - 1]).nextModelPosition_.Z = (float) Convert.ToDouble(savedStuff[7]);
        }*/
        #endregion
    }
}

